+++
title = "How to use rsync"
date = 2021-02-05
+++

Most common use cases
=====================

The following use cases sum up what I do the most with rsync. I
personally use it mostly for pushing content.

Update a remote
---------------

The following shows how to update the remote content, for example, for a
blog. It removes the old, adds the new, and leaves things only on the
remote. Just replace the path for remote with the host and path for the
blog.

```
me@here:~/$ ./demo 
#!/usr/bin/env bash
set -e
set -u
set -o pipefail


cat demo

echo "Run the demo..."

mkdir temp \
    && cd temp \
    && mkdir local \
    && mkdir remote \
    && touch local/foo \
    && touch local/bar \
    && touch remote/old \
    && mkdir remote/.well-known \
    && tree -a \
    && rsync -avh --delete --exclude=".well-known" local/ remote/ \
    && tree -a \
    && cd .. \
    && rm -r temp \
        || echo "failed"

# end of demo
Run the demo...
.
├── local
│   ├── bar
│   └── foo
└── remote
    ├── old
    └── .well-known

3 directories, 3 files
sending incremental file list
deleting old
bar
foo

sent 178 bytes  received 61 bytes  478.00 bytes/sec
total size is 0  speedup is 0.00
.
├── local
│   ├── bar
│   └── foo
└── remote
    ├── bar
    ├── foo
    └── .well-known

3 directories, 4 files
```

Use a specific ID
-----------------

Sometimes I have an ssh key that I use. The following sums up how I
specify that key and specify a port. I\'ll hope someone knows a better
way and lets me know some day.

```
rsync -avh -e "ssh -i $HOME/.ssh/id_file_here -p 4321" --delete local/ username@0.0.0.0:/path/
```
